'use strict';
module.exports = {
	/**
	 * 搜索结果
	 * @url client/course/pub/search-result 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid, pageIndex, pageSize, category_id, keyword } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------
		let fieldJson = {}
		let dbName = "course";
		let whereJson = {
			title: new RegExp(keyword) // 搜索条件
		}
		if (category_id != '') {
			whereJson.category_parent_id = category_id // 分类ID
		}
		res = await vk.baseDao.select({
			dbName: dbName, // 表名
			getMain: false, // 是否只返回rows数据
			pageIndex, // 当前第几页
			pageSize, // 每页条数
			foreignDB: [{
				dbName: "course_category",
				localKey: "category_id",
				foreignKey: "_id",
				as: "category",
				limit: 1,
			}],
			sortArr: [{ "name": "_add_time", "type": "desc" }],
			// 条件
			whereJson: whereJson
		});

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
